package zqservlet;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import zqdb.O_INFO;
import zqdb.T_ONE;
import zqdb.T_TWO;
import zqtools.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@WebServlet(name = "rightServlet", urlPatterns = "/right")
public class rightServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String as_jud = request.getParameter("JUD");
        String as_cmd = request.getParameter("CMD");
        String as_value01 = request.getParameter("VALUE01");

        O_INFO of = new O_INFO();
        of.setCMD(as_cmd);
        of.setVALUE01(as_value01);

        JSONObject j = DBUtil.f_query(of);
        JSONArray jobj1 = j.getJSONArray("db1");
        JSONArray jobj2 = j.getJSONArray("db2");
        StringBuilder ls_nav = new StringBuilder();


        if ("CDQX".equals(as_jud))      //--菜单权限的界面
        {
            for (int i = 0; i < jobj1.size(); i++) {
                JSONObject o1 = jobj1.getJSONObject(i);
                String ls_node = o1.get("VALUE01").toString();
                ls_nav.append("<dl class='permission-list'><dt><label class='' style='font-size:16px'><input type='checkbox' ")
                        .append(" value='").append(o1.get("VALUE01").toString()).append("' ")
                        .append(" v-model='checkFu'")
                        .append(" @click='fuClick'")
                        .append(" name='user-Character-0-0' id='item")
                        .append(o1.get("VALUE01").toString())
                        .append("'>")
                        .append(o1.get("VALUE03").toString())
                        .append("</label></dt><dd>");

                for (int k = 0; k < jobj2.size(); k++) {
                    JSONObject o2 = jobj2.getJSONObject(k);
                    String ls_pnode = o2.get("VALUE02").toString();
                    if (ls_pnode.equals(ls_node)) {
                        ls_nav.append("<label style='font-size:16px' ><input type='checkbox' ")
                                .append(" v-model='checkZi'")
                                .append(" @click='ziClick'")
                                .append(" value='").append(o2.get("VALUE01").toString()).append("'")
                                .append(" name='user-Character-0-0-0' id='item")
                                .append(o2.get("VALUE01").toString())
                                .append("'>")
                                .append(o2.get("VALUE03").toString())
                                .append("</label><br>");
                    }
                }
                ls_nav.append("</dd></dl>");
            }
            request.setAttribute("nav", ls_nav.toString());
            request.getRequestDispatcher("/w_zxkj_usercdqx.jsp").forward(request, response);

        } else if ("YWQX".equals(as_jud)) {
            for (int i = 0; i < jobj1.size(); i++) {
                JSONObject o1 = jobj1.getJSONObject(i);
                String ls_node = o1.get("VALUE01").toString();
                ls_nav.append("<dl class='permission-list'><dt><label class='' style='font-size:16px'>")
                        .append(o1.get("VALUE03").toString())
                        .append("</label></dt><dd>");

                for (int k = 0; k < jobj2.size(); k++) {
                    JSONObject o2 = jobj2.getJSONObject(k);
                    String ls_pnode = o2.get("VALUE02").toString();
                    if (ls_pnode.equals(ls_node)) {
                        ls_nav.append("<van-button type= 'primary' @click='ywClick()' style='width: 80%; margin-top:8px' value='").append(o2.get("VALUE01").toString()).append("' >")
                                .append(o2.get("VALUE03").toString())
                                .append("</van-button><br>");
                    }
                }
                ls_nav.append("</dd></dl>");
            }
            request.setAttribute("nav", ls_nav.toString());
            request.getRequestDispatcher("/w_zxkj_userywqx.jsp").forward(request, response);
        }
    }
}
